//
//  TCM_MineViewController.swift
//  TCM_TradingProject
//
//  Created by 吕春海 on 2018/8/17.
//  Copyright © 2018年 lvchunhai. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa

class TCM_MineViewController: TCM_BaseViewController,UITableViewDelegate,UITableViewDataSource {
    var mineTableView:UITableView!
    let disposeBag = DisposeBag()
    let entryNameArry:[String] = ["我的订单", "我的拍卖", "我的采购", "我的供应", "我的发票"]
    let entryImageArry:[String] = ["TCM_MineOrder", "TCM_MineAuction", "TCM_MineProcurement", "TCM_MineSupply", "TCM_MineInvoice"]
    let otherNameArry:[String] = ["我的钱包", "我的收藏", "申请仓库", "申请初检", "我的货物", "物流管理"]
    let otherImageArry:[String] = ["TCM_MineWallet", "TCM_MineCollection", "TCM_MineWarehouse", "TCM_MineDetection", "TCM_MineGoods", "TCM_MineLogistics"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white

        initialTableView()
        // Do any additional setup after loading the view.
        let button:UIButton = UIButton(type:.custom)
        //设置按钮位置和大小
        button.frame = CGRect(x: TCM_ScreenWidth - 80, y: 80, width: 100, height: 50)
        //设置按钮文字
        button.setTitle("登录", for: .normal)
        self.view.addSubview(button)
        
        button.rx.tap
            .bind{ [weak self] in
                let loginVC = TCM_LoginViewController()
                self?.navigationController?.pushViewController(loginVC, animated: true)
            }
            .disposed(by: disposeBag)
    }

    //视图将要显示
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        navigationController?.setNavigationBarHidden(true, animated: false)
    }
    
    //视图将要消失
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        navigationController?.setNavigationBarHidden(false, animated: false)
    }
    
    func initialTableView() {
        self.mineTableView = UITableView(frame: self.view.frame, style:.grouped)
        self.mineTableView.contentInset = UIEdgeInsets(top: -TCM_StatusHeight(), left: 0, bottom: 0, right: 0)
        self.mineTableView.backgroundColor = TCM_HexRGB(0xF0F0F0)
        self.mineTableView.separatorStyle = UITableViewCellSeparatorStyle.none
        self.mineTableView.showsVerticalScrollIndicator = false
        self.mineTableView.isScrollEnabled = false
        self.mineTableView.delegate = self
        self.mineTableView.dataSource = self
        self.view.addSubview(mineTableView)
        
        self.mineTableView.register(UINib.init(nibName: "TCM_MineTableViewCell", bundle: nil), forCellReuseIdentifier: "mineCell")
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 6
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 48
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = (mineTableView.dequeueReusableCell(withIdentifier: "mineCell", for: indexPath)) as! TCM_MineTableViewCell
        cell.otherLabel.text = otherNameArry[indexPath.row]
        cell.otherImageView.image = UIImage.init(named: otherImageArry[indexPath.row])
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 228 + TCM_StatusHeight()
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = Bundle.main.loadNibNamed("TCM_MineHeaderView",owner: self, options: nil)?[0] as! TCM_MineHeaderView
        headerView.entryNameArr = self.entryNameArry
        headerView.entryImageArr = self.entryImageArry
        return headerView
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.00001
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return nil
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
